<#include "../common/_public.html"/>
    <link rel="stylesheet" href="${base}/layui/css/layui.css"  media="all">

<title>设置我的资料</title>
<form class="layui-form" id="LAY_user_info_form">
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">设置我的资料</div>
                <div class="layui-card-body" pad15>
                    <div class="layui-fluid">
                        <div class="layui-row">
                            <div class="layui-col-sm6">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">用户名</label>
                                    <div class="layui-input-inline">
                                        <input type="hidden" id="user_info_id" value="${entity.uId!}" name="uId">
                                        <input type="text" name="username" value="${entity.userName!}" disabled readonly class="layui-input layui-disabled">
                                    </div>
                                    <label class="layui-form-label">我的角色</label>
                                    <div class="layui-input-inline">
                                        <div class="layui-input-inline">
                                            <input type="text" name="role" value="${role!}" disabled readonly autocomplete="off" class="layui-input layui-disabled">
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-form-item">

                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">昵称</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="uNickname" value="${entity.uNickname!}" lay-verify="nickname" autocomplete="off" placeholder="请输入昵称" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">真实姓名</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="uName" value="${entity.uName!}"  autocomplete="off" placeholder="请输入姓名" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">出生年月</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="uBirthday" value="${(entity.uBirthday?string('yyyy-MM-dd HH:mm:ss'))!}" readonly id="user_birthday_info" class="layui-input">
                                    </div>

                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">性别</label>
                                    <div class="layui-input-block">
                                        <input type="radio" name="uSex" value="0" title="男"<#if entity.uSex?? && entity.uSex == 0>checked</#if>>
                                        <input type="radio" name="uSex" value="1" title="女" <#if entity.uSex?? && entity.uSex == 1>checked</#if>>
                                        <input type="radio" name="uSex" value="2" title="保密" <#if entity.uSex?? && entity.uSex == 2>checked</#if>>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">年龄</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="uAge" value="${entity.uAge!}" lay-verify="number" autocomplete="off" placeholder="请输入年龄" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">手机</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="uPhone" value="${entity.uPhone!}" lay-verify="phone" placeholder="请输入手机号" autocomplete="off" class="layui-input">
                                    </div>

                                    <label class="layui-form-label">邮箱</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="uEmail" value="${entity.uEmail!}" lay-verify="email" placeholder="请输入邮箱" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-sm6">
                                <input type="hidden"  id="uHeadportrait" name="uHeadportrait" value="${entity.uHeadportrait!'defalut.jpg'}">
                                <label class="layui-form-label">头像</label>
                                <img id="user_headportrait_info" src="${base}/layui/images/avatar/${entity.uHeadportrait!'defalut.jpg'}" style="height: 300px; width:300px;">
                                    <button type="button" class="layui-btn layui-btn-primary" id="LAY_avatarUpload">
                                        <i class="layui-icon">&#xe67c;</i>选择图片
                                    </button>
                                </div>
                            </div>
                        </div>

                        <div class="layui-form-item layui-form-text">
                            <label class="layui-form-label">简介</label>
                            <div class="layui-input-block">
                                <textarea name="uIntro" placeholder="请输入内容"  class="layui-textarea">${entity.uIntro!}</textarea>
                            </div>
                        </div>
                            <center>
                            <input type="hidden" id="rate_curr_info" value="${entity.uRate!'0'}">
                            <font style="font-weight: bold" size="3"> 等 级：【<span style="color: blue">${entity.uRank!'1'}</span>】<font>
                                &emsp;&emsp;
                            <font style="font-weight: bold" size="3"> 积 分：【<span style="color: blue">${entity.uScore!'0'}</span>】<font>
                                &emsp;&emsp;
                            <font style="font-weight: bold" size="3"> 评 分：<font><div id="user_rate_info"/>
                            </center>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" id="user_info_submit" lay-submit lay-filter="setmyinfo">确认修改</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</form>
<script src="${base}/layui/layui.js" charset="UTF-8"></script>
<script>
    layui.use(['laydate','layer','form','rate','upload','element'], function(){
        var rate = layui.rate,
                layer = layui.layer,
                form = layui.form,
                $ = layui.$,
                laydate = layui.laydate,
                upload = layui.upload;
        var rate_value = $("#rate_curr_info").val();
        var user_info_id = $("#user_info_id").val();
        laydate.render({
            elem: '#user_birthday_info' //指定元素
            ,type: 'datetime'
        });
        rate.render({
            elem: '#user_rate_info'  //绑定元素
            ,length:5
            ,value:rate_value
            ,half:true
            ,readonly:true
        });
        //上传组件
        var uploadInst = upload.render({
            elem: '#LAY_avatarUpload' //绑定元素
            ,url: '${base}/upload/upload_uploadImage.do' //上传接口
            ,accept:'images'
            ,exts:'jpg|png|gif'
            // ,acceptMime:'image/jpeg ,image/jpg, image/png'
            ,choose: function(obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#user_headportrait_info').attr('src', result); //图片链接（base64）
                })
            }
            ,data:{
                id:user_info_id,
                oldFileName :function(){
                    var oldFileName = $('#uHeadportrait').val();
                    return oldFileName;
                }
            }
            ,done: function(result){
                    if(result.statusCode == 200){
                        $('#uHeadportrait').attr('value', result.forward);
                        layer.msg(result.message,{
                            icon:1,
                            time:1500,
                        })
                    }else if(result.statusCode == 300){
                        layer.msg(result.message,{
                            icon:2,
                            time:2000,
                        });
                    }
            }
        });
        form.verify({
            number:function (value) {
                if(value <= 0 || value >= 100){
                    return '年龄在0 ~ 100之间';
                }
            }
            ,pass: [/(.+){6,18}$/, '密码必须6到12位']
            ,phone:function (value) {
                if(value.length != 0) {
                    if (!new RegExp("^1[3|7|5|8][0-9]\\d{8}$").test(value)) {
                        return '请输入正确的手机号';
                    }
                }
            }

            ,email:function (value) {
                if(value.length != 0) {
                    if (!new RegExp("^([a-z0-9_\\.-]+)@([\\da-z\\.-]+)\\.([a-z\\.]{2,6})$").test(value)) {
                        return '请输入正确的邮箱地址';
                    }
                }
            }
        });

        //监听提交
        form.on('submit(setmyinfo)', function(data){
            $.ajax({
                url:'${base}/system/user_saveAndUpdate.do',
                type:'post',
                data:$("#LAY_user_info_form").serialize(),
                dataType:"json",
                success:function(result) {
                    if(result.statusCode == 200){
                        layer.msg(result.message,{
                            icon:1,
                            time:1500
                        },function () {
                            parent.tools.refresh_parent_now();
                            parent.tools.closed();
                        })
                    }else if(result.statusCode == 300){
                        layer.msg(result.message,{
                            icon:2,
                            time:2000
                        });
                    }
                }
            });
            return false;
        });
    });
</script>